package util;
public class Vector
{
	private double x, y;
	
	public Vector()
	{
		x = 0;
		y = 0;
	}
	
	public Vector(double someX, double someY)
	{
		x = someX;
		y = someY;
	}
	
	public double magnitude()
	{
		return Math.sqrt(x * x + y * y);
	}
	
	public Vector normalize()
	{
		double magnitude = magnitude();
		
		if (magnitude != 0)
		{
			divide(magnitude);
		}
		return new Vector(x, y);
	}
	
	public Vector limit(double m)
	{
		if (magnitude() > m)
		{
			normalize();
			multiply(m);
			return new Vector(x, y);
		}
		else return new Vector(x, y);
	}
	
	public Vector cutOff(double minMagnitude)
	{
		if (this.magnitude() < minMagnitude)
		{
			x = 0;
			y = 0;
			return new Vector();
		}
		
		return this.clone();
	}
	
	public Vector distance(Vector other)
	{
		double dx = Math.abs(x - other.getX());
		double dy = Math.abs(y - other.getY());
		
		return new Vector(dx, dy);
	}
	
	public double euclDistance(Vector other)
	{		
		return distance(other).magnitude();
	}
	
	public Vector substract(Vector other)
	{
		x -= other.getX();
		y -= other.getY();
		
		return new Vector(x, y);
	}
	
	public static Vector substract(Vector one, Vector two)
	{
		double x = one.getX() - two.getX();
		double y = one.getY() - two.getY();
		
		return new Vector(x, y);
	}
	
	public Vector add(Vector other)
	{
		x += other.getX();
		y += other.getY();
		
		return new Vector(x, y);
	}
	
	public static Vector add(Vector one, Vector two)
	{
		double x = one.getX() + two.getX();
		double y = one.getY() + two.getY();
		
		return new Vector(x, y);
	}
	
	public Vector divide(double m)
	{
		x /= m;
		y /= m;	
		
		return new Vector(x, y);
	}
	
	public Vector multiply(double m)
	{
		x *= m;
		y *= m;
				
		return new Vector(x, y);
	}
	
	public static Vector multiply(Vector v, double m)
	{
		return v.clone().multiply(m);
	}
	
	public double dot(Vector other)
	{
		return x * other.getX() + y * other.getY();
	}
	
	public Vector clone()
	{
		return new Vector(x, y);
	}
	
	public void set(double x, double y)
	{
		this.x = x;
		this.y = y;
	}
	
	public double getX()
	{
		return x;
	}
	
	public double getY()
	{
		return y;
	}
	
	public String toString()
	{
		return "X: " + x + ", Y: " + y + ", Magn: " + magnitude();
	}
	
	public static void main(String[] args)
	{
		Vector a = new Vector(1, 0);
		System.out.println("cutoff " + a.cutOff(0.5));
		System.out.println(a.cutOff(2.0));
	}
}
